package com.shop2cn.app.liveseller.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.app.liveseller.parameter.SetIsLiveInheritBean;
import com.shop2cn.app.liveseller.service.SetIsLiveInheritCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.LiveRoom;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
/**
*设置直播间是否允许联播
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetIsLiveInherit{
	private static SetIsLiveInheritBean setisliveinheritBean;
	private static SetIsLiveInheritCall setisliveinheritCall;
	private static int sellerId ;
	private static String token ;
	private static int csId;
	private static String cstoken;
	static LiveRoomShop2cnWapper LiveRoomShop2cnWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置直播间是否允许联播");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
			csId = GodmchManageCallService.bindClientService(
					sellerId, 1);
			cstoken = AuthCallServiceV2.createToken(csId, "app");
			LiveRoomShop2cnWapper=new LiveRoomShop2cnWapper();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		setisliveinheritBean=new SetIsLiveInheritBean();
		setisliveinheritCall=new SetIsLiveInheritCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setisliveinheritCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetIsLiveInherit_001() {
		Logger.start(true,"设置直播间是否允许联播成功liveInherit1");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			setisliveinheritBean.setLiveInherit(1);
			setisliveinheritBean.setLiveRoomId(createlive.getId());
			String head="accesstoken="+token;
			setisliveinheritCall.addHeader("ymt-pars", head);
			setisliveinheritCall.setData(setisliveinheritBean);
			setisliveinheritCall.callService();			
			Logger.verifyEquals("{}", setisliveinheritCall.getReturnData(), "验证Code");
			LiveRoom dblive = LiveRoomShop2cnWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(true, dblive.getLiveInherit(), "验证getLiveInherit");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetIsLiveInherit_002() {
		Logger.start(true,"不输入liveRoomId失败");
		try {
			setisliveinheritBean.setLiveInherit(1);
//			setisliveinheritBean.setLiveRoomId(createlive.getId());
			String head="accesstoken="+token;
			setisliveinheritCall.addHeader("ymt-pars", head);
			setisliveinheritCall.setData(setisliveinheritBean);
			setisliveinheritCall.callService();			
			Logger.verifyEquals("400", setisliveinheritCall.getString("code"), "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetIsLiveInherit_003() {
		Logger.start(true,"不输入liveInherit失败");
		try {
//			setisliveinheritBean.setLiveInherit(1);
			setisliveinheritBean.setLiveRoomId(1);
			String head="accesstoken="+token;
			setisliveinheritCall.addHeader("ymt-pars", head);
			setisliveinheritCall.setData(setisliveinheritBean);
			setisliveinheritCall.callService();			
			Logger.verifyEquals("400", setisliveinheritCall.getString("code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetIsLiveInherit_004() {
		Logger.start(true,"设置直播间是否允许联播成功liveInherit0");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			setisliveinheritBean.setLiveInherit(1);
			setisliveinheritBean.setLiveRoomId(createlive.getId());
			String head="accesstoken="+token;
			setisliveinheritCall.addHeader("ymt-pars", head);
			setisliveinheritCall.setData(setisliveinheritBean);
			setisliveinheritCall.callService();			
			Logger.verifyEquals("{}", setisliveinheritCall.getReturnData(), "验证Code");
			setisliveinheritBean.setLiveInherit(0);
			setisliveinheritCall.callService();	
			LiveRoom dblive = LiveRoomShop2cnWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(false, dblive.getLiveInherit(), "验证getLiveInherit");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}